package com.springcloud.provider.controller;

import com.springcloud.provider.components.SnowflakeComponent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@Slf4j
public class HelloController {
    @Autowired
    private SnowflakeComponent snowflakeComponent;

    @GetMapping("/hello")
    public String provider(String name, Long time){
        log.info("provider in");
        if (time == null){
            time = 10L;
        }
        try {
            Thread.sleep(time);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        providerService();
        log.info("provider out");
        return "provide name:" + name + "snowid: " + snowflakeComponent.getInstance().nextId();
    }

    private void providerService(){
        log.info("come in providerService");
        System.out.println("date:"+new Date());
    }
}
